package com.lanhao.aot.excel;

import java.io.File;
import java.util.List;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

public class CellDataTypeTest {
	public static void main(String[] args) {
		String filePath = "D:/test.xlsx";
		ExcelReader reader = ExcelUtil.getReader(new File(filePath));
		List<List<Object>> itemDataList = reader.read();
		// 处理明细单文件
		for (int i = 1; i < itemDataList.size(); i++) {
			List<Object> data = itemDataList.get(i);
			String trackingNo = getExcelStringValue(data, 0);
			String weight = getExcelStringValue(data, 1);
			String carryFee = getExcelStringValue(data, 2);
			String fuelSurcharge = getExcelStringValue(data, 3);
			String otherFee = getExcelStringValue(data, 4);
			System.out.println(trackingNo + "-" + weight + "-" + carryFee + "-" + fuelSurcharge + "-" + otherFee);
		}
	}
	
	private static String getExcelStringValue(List<Object> list, int index) {
		String value = "";
		if (list.size() > index) {
			Object o = list.get(index);
			System.out.println(index);
			System.out.println(o);
			if (o instanceof Long) {
				value = String.valueOf((Long) o);
			} if (o instanceof Double) {
				value = String.valueOf((Double) o);
			} else {
				value = (String) o;
			}
		}
		return value;
	}
}
